package com.tansuo365.test1.controller.othercontrol;

import com.tansuo365.test1.bean.otherbean.Wuliaodanwei;
import com.tansuo365.test1.service.otherservice.WuliaodanweiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 物料单位
 */
@RestController
@RequestMapping("/admin/wuliaodanwei")
public class WuliaodanweiController {

    @Autowired
    private WuliaodanweiService wuliaodanweiService;

    /**
     * @return
     * @throws Exception
     */
    @RequestMapping("/comboList")
    public List<Wuliaodanwei> comboList() throws Exception {
        return wuliaodanweiService.listAll();
    }

    /**
     * 查询所有物料单位
     *
     * @return
     * @throws Exception
     */
    @RequestMapping("/listAll")
    public Map<String, Object> listAll() throws Exception {
        List<Wuliaodanwei> wuliaodanweiList = wuliaodanweiService.listAll();
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("rows", wuliaodanweiList);
        return resultMap;
    }

    /**
     * 添加物料单位
     *
     * @return
     * @throws Exception
     */
    @RequestMapping("/save")
    public Map<String, Object> save(Wuliaodanwei wuliaodanwei) throws Exception {
        Map<String, Object> resultMap = new HashMap<>();
        wuliaodanweiService.save(wuliaodanwei);
        resultMap.put("success", true);
        return resultMap;
    }

    /**
     * 删除物料单位信息
     *
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping("/delete")
    public Map<String, Object> delete(int id) throws Exception {
        Map<String, Object> resultMap = new HashMap<>();
        int delete = wuliaodanweiService.delete(id);
        if (delete > 0) {
            resultMap.put("success", true);
            return resultMap;
        } else {
            resultMap.put("success", false);
            return resultMap;
        }
    }

}
